﻿using GameData.Common;
using GameData.Domains.Mod;
using GameData.Domains.SpecialEffect.LegendaryBook.NpcEffect;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TaiwuModFramework.Common;
using TaiwuModFramework.Common.Abstract;
using TaiwuModFramework.Common.Base;
using TaiwuModFramework.Common.Manager;

namespace TaiwuModFramework.Backend.Comp {
    internal class CallModMethodComp : BaseTaiwuComp {
        private static ALogger Log;
        private static Dictionary<string, ModInfo> modInfos = null;

        private static void CheckModInfo(ModDomain domain) {
            modInfos ??= Traverse.Create(domain).Field("ModInfoDict").GetValue<Dictionary<string, ModInfo>>();
        }

        [HarmonyPostfix]
        [HarmonyPatch(typeof(ModDomain), "UpdateModSettings")]
        public static void ModDomain_UpdateModSettings_Postfix(ModDomain __instance,DataContext context, ModId modId, SerializableModData modData) {
            CheckModInfo(__instance);
            try {
                ConfigManager.UpdateItem(modId.ToString());
            } catch(Exception e) {
                Log.Error(e);
            }
            
        }
    }
}
